package com.plug.utils.elasticsearch;
/*
    *//**  
    * @Title: ElasticsearchService.java
    * @Package com.third.elasticsearch.util
    * @Description: 
    * @author likai
    * @date 2017年5月19日
    * @version V1.0  
    *//*
    
package com.third.elasticsearch.util;



import java.util.ArrayList;  
import java.util.List;  
  
import org.apache.log4j.Logger;  
import org.elasticsearch.action.ActionFuture;  
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;  
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;  
import org.elasticsearch.client.Client;  
import org.springframework.beans.factory.annotation.Autowired;  
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;  
import org.springframework.data.elasticsearch.core.query.IndexQuery;  
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;  

  
	
	*//**
	* @ClassName: ElasticsearchService
	* @Description: 
	* @author likai
	* @date 2017年5月19日
	*
	*//*
public class ElasticsearchService {  
  
    private static final Logger logger = Logger.getLogger(ElasticsearchService.class);  
  
    @Autowired  
    private ElasticsearchTemplate elasticsearchTemplate;  
  
    @Autowired  
    private Client esClient;  
  
    public void init() {  
        if (!elasticsearchTemplate.indexExists(APP.ESProp.INDEX_NAME)) {  
            elasticsearchTemplate.createIndex(APP.ESProp.INDEX_NAME);  
        }  
        elasticsearchTemplate.putMapping(TaskInfo.class);  
       // elasticsearchTemplate.putMapping(NewsInfo.class);  
    }  
  
    public boolean update(List<TaskInfo> taskInfoList) {  
        List<IndexQuery> queries = new ArrayList<IndexQuery>();  
        for (TaskInfo taskInfo : taskInfoList) {  
            IndexQuery indexQuery = new IndexQueryBuilder().withId(taskInfo.getTaskId()).withObject(taskInfo).build();  
            queries.add(indexQuery);  
        }  
        elasticsearchTemplate.bulkIndex(queries);  
        return true;  
    }  
  
    public boolean insertOrUpdateTaskInfo(List<TaskInfo> taskInfoList) {  
        List<IndexQuery> queries = new ArrayList<IndexQuery>();  
        for (TaskInfo taskInfo : taskInfoList) {  
            IndexQuery indexQuery = new IndexQueryBuilder().withId(taskInfo.getTaskId()).withObject(taskInfo).build();  
            queries.add(indexQuery);  
        }  
        elasticsearchTemplate.bulkIndex(queries);  
        return true;  
    }  
  
    public boolean insertOrUpdateNewsInfo(List<NewsInfo> newsInfos) {  
        List<IndexQuery> queries = new ArrayList<IndexQuery>();  
        for (NewsInfo newsInfo : newsInfos) {  
            IndexQuery indexQuery = new IndexQueryBuilder().withId(newsInfo.getNewsId()).withObject(newsInfo).build();  
            queries.add(indexQuery);  
        }  
        elasticsearchTemplate.bulkIndex(queries);  
        return true;  
    }  
  
    public boolean insertOrUpdateNewsInfo(NewsInfo newsInfo) {  
        try {  
            IndexQuery indexQuery = new IndexQueryBuilder().withId(newsInfo.getNewsId()).withObject(newsInfo).build();  
            elasticsearchTemplate.index(indexQuery);  
            return true;  
        } catch (Exception e) {  
            logger.error("insert or update news info error.", e);  
            return false;  
        }  
    }  
  
    public boolean insertOrUpdateTaskInfo(TaskInfo taskInfo) {  
        try {  
            IndexQuery indexQuery = new IndexQueryBuilder().withId(taskInfo.getTaskId()).withObject(taskInfo).build();  
            elasticsearchTemplate.index(indexQuery);  
            return true;  
        } catch (Exception e) {  
            logger.error("insert or update task info error.", e);  
            return false;  
        }  
    }  
  
    
  
    public <T> boolean deleteById(String id, Class<T> clzz) {  
        try {  
            elasticsearchTemplate.delete(clzz, id);  
            return true;  
        } catch (Exception e) {  
            logger.error("delete " + clzz + " by id " + id + " error.", e);  
            return false;  
        }  
    }  
  
   
}  
*/